#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>

#define MAX_SIZE 1000
typedef struct 
{
    int size;
    int *arr;
}ArrayStack;

/*构造函数*/
ArrayStack *newArrayStack()
{
    ArrayStack *s = (ArrayStack *)malloc(sizeof(ArrayStack));
    s->size = 0;
    s->arr = (int *)malloc(MAX_SIZE*sizeof(int));
}
/*析构函数*/
void delArrayStack(ArrayStack *s)
{
    free(s->arr);
    free(s);
}
/*获取size*/
int size(ArrayStack *s)
{
    return s->size;
}
/*是否为空*/
bool isEmpty(ArrayStack *s)
{
    return s->size == 0;
}
/*入栈*/
void push(ArrayStack *s, int num)
{
    s->arr[s->size] = num;
    s->size++;
}
/*获取栈顶的值*/
int peek(ArrayStack *s)
{
    if (s->size == 0)
    {
        printf("栈为空\n");
        return INT_MAX;
    }
    return s->arr[s->size-1];
}
/*出栈*/
int pop(ArrayStack *s)
{
    int val = peek(s);
    s->size--;
    return val;
}
/*打印栈*/
void print_stack(ArrayStack *s)
{
    for (int i = s->size-1; i >= 0; i--)
    {
        printf("%d>", s->arr[i]);
    }
    printf("\n");
}

int main(int argc, char const *argv[])
{
    // 初始化栈1>3>2>5>4
    ArrayStack *stack = newArrayStack();
    push(stack, 4);
    push(stack, 5);
    push(stack, 2);
    push(stack, 3); 
    push(stack, 1);
    print_stack(stack);

    return 0;
}
